<template>
  <div style="margin-bottom: 20px;">
    <el-dialog :title="edit_main_title" append-to-body v-dialogDrag :visible.sync="edit_flag" :close-on-click-modal="false"
               width="400px"  @open="handleOpenConfig" :before-close="handleClose">
      <el-form label-width="100px" ref="objEditFrom" class="web_form" style="margin-top: 10px;"
               :rules="objEditRules" :model="objEditData" :disabled="editMakeDisabled">
        <el-form-item label="库位类型：" prop="type">
          <el-select v-model="objEditData.type" class="w184" clearable filterable remote reserve-keyword placeholder="请选择库区类型">
            <el-option v-for="(item,index) in objEditWays.type" :key="index" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <!--按钮-->
      <el-row type="flex" justify="end">
        <!--<el-button type="primary" @click="handleClose">关闭</el-button>-->
        <el-button class="mr30" v-if="edit_main_title !== '查看'" type="primary" @click="confirmClick">提交</el-button>
      </el-row>
      <div style="height:20px"></div>
    </el-dialog>
  </div>
</template>

<script>
  import * as StoreAreaAPI from '@/api/house/storeArea'
  import * as Utils from '@/utils/index'
  export default {
    name: '',
    props: ['edit_flag', 'edit_main_title', 'edit_select_row', 'edit_params'],
    components: {},
    data() {
      return {
        objEditData: {
          type: null
        },
        objEditRules: {
          type: [{ required: true, message: '请先选择库位类型', trigger: 'blur' }]
        },
        objEditWays: {
          type: [
            { value: '10', label: '普通库位' },
            { value: '20', label: '临时库位' },
            { value: '30', label: '虚拟库位' },
            { value: '40', label: '大库位' },
            { value: '50', label: '中库位' }
          ]
        },
        ids: [],
        queryInputListOne: [], // 输入值 远程模糊查询的 下拉条件列表
        SelectListOne: [], // 已查询好 直接下拉选择列表
        makeInputDisabled: false, // -input 禁用
        editMakeDisabled: false // 面板禁用
      }
    },
    methods: {
      // 弹窗页打开初始
      handleOpenConfig(data) {
        const that = this
        console.log(that.$props.edit_main_title, 'that.$props', that.$props.edit_select_row, that.$props.edit_params, that.$props.companyId)
        const { ids } = that.$props.edit_params // attachmentId
        that.ids = ids
        that.getSelectListFunc()
        // 重置
        that.editMakeDisabled = false
        that.makeInputDisabled = false
        that.objEditData = Utils.resetObjEditDataFunc(that.objEditData)
      },
      // selectList 下拉选择列表
      getSelectListFunc() {
        // TrainPriseAPI.selectDrivers({}).then((res) => {
        //   if (res.data.code === 0) {
        //     this.driverPlateListSave = res.data.data
        //     this.SelectListOne = Utils.arrayUnique2(res.data.data, 'driverName') // 根据idKey 对象数组去重
        //   }
        // })
      },
      // 选择 设置名称导出 $event,scope.row,'modelNo'
      selectCorp($event, value) {
        console.log('selectCorp(value)', $event, value)
        // const that = this
        // if (value === 'licensePlate') {
        //   that.SelectListOne.map(item => {
        //     if ($event === item.licensePlate) {
        //       that.objEditData.truckModelId = item.truckModelId
        //     }
        //   })
        // }
      },
      confirmClick() {
        const that = this
        that.$refs['objEditFrom'].validate((valid) => {
          if (valid) {
            const toParams = {
              keys: Utils.arrayToStringFunc(that.ids),  // ids
              type: 'location', // 库位
              locationType: that.objEditData.type // 库位类型
            }
            StoreAreaAPI.batchUpdateLocationType(toParams).then(res => {
              that.$message({
                message: '批量修改成功',
                type: 'success',
                duration: 2000
              })
              that.$emit('edit-confirm', false)
            }).catch(err => {
              console.log('error', err)
            })
          }
        })
      },
      handleClose() {
        const that = this
        that.$emit('edit-close', false)
      }
    }
  }
</script>

<style scoped>
</style>
